<?php
//
defined('BY_JYA') or exit('error');
//cfc('core')->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';

if($_RQ['op']=='main'){
	if(isset($_RQ['status']) && $_RQ['status']!='all'){
		$params['status']=$_RQ['status'];
		$return['params']['status']=$_RQ['status'];
	}else{
		$return['params']['status']='all';
	}
	$return['list']=array();
	exi($return);
}
if($_RQ['op']=='list'){
	$this->model('task')->orderup();
	//$post=get_postdata();
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'isdel'=>0);
	if(isset($_RQ['status']) && $_RQ['status']!='all'){
		$params['status']=$_RQ['status'];
		$return['params']['status']=$_RQ['status'];
	}else{
		$return['params']['status']='all';
	}
	if($_RQ['ispay']){
		$params['ispay']=$_RQ['ispay'];
		$return['params']['ispay']=$_RQ['ispay'];
	}
	//if(!empty($_RQ['keyword'])){
	//	$params['title like']='%'.trim($_RQ['keyword']).'%';
	//	$return['params']['title']=$_RQ['keyword'];
	//}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$total='';
	$return['list']=pdo_getslice('jy_jd_order',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	foreach($return['list'] as &$v){
		$v['hotel']=pdo_get('jy_jd_hotel',array('id'=>$v['hotelid']));
		$v['room']=pdo_get('jy_jd_room',array('id'=>$v['roomid']));
		$v['createtime']=date('Y-m-d H:m:s',$v['createtime']);
		$v['statustitle']=$this->order_status[$v['status']];
	}
	exi($return);
}
if($_RQ['op']=='del'){
	if(!$_RQ['id']){
		exi('请先选择订单','error');
	}
	$order=pdo_get('jy_jd_order',array('id'=>$_RQ['id']));
	pdo_update('jy_jd_order',array('isdel'=>1),array('id'=>$_RQ['id']));
	exi('删除成功');
}
if($_RQ['op']=='receive'){
	if(!$_RQ['id']){
		exi('请先选择订单','error');
	}
	$order=pdo_get('jy_jd_order',array('id'=>$_RQ['id']));
	if($order['status']!=0 && $order['status']!=1){
		exi('当前订单不可取消','error');
	}
	$room=pdo_get('jy_jd_room',array('id'=>$order['roomid']));
	if(!$room['is_opentui']){
		exi('该房间不支持退订！','error');
	}
	if($room['tui_day'] || $room['tui_day']){
		$intime=strtotime($order['intime']);
		$tui_daytime=$intime-$room['tui_day']*24*3600;
		$tui_day=date('Y-m-d',$tui_daytime);
		$tui_daytime2=strtotime($tui_day.' '.$room['tui_time']);
		if($tui_daytime2<time()){
			exi('退订时间已过！','error');
		}
	}
	$this->model('notice')->notice_receiveorder($order);
	if($order['ispay']==1){
		$this->model('refund')->check_order_rerefund($order['id']);
		pdo_update('jy_jd_order',array('status'=>2),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		$this->model('notice')->notice_receiveorder2admin($order);
		exi('已申请取消');
	}
	if($order['ispay']==0){
		pdo_update('jy_jd_order',array('status'=>7),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		exi('已取消');
	}
}
if($_RQ['op']=='pay'){
	$id = intval($_RQ['id']);
	if(!$id){
		exi('订单不存在，请重新选择订单','error');
	}
	$order=pdo_get('jy_jd_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	if($order['status']){
		exi('该订单已过支付时间！','error');
	}
	exi($order['pay_id']);
}
?>